package com.smz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smz.dao.TCargoDAO;
import com.smz.entity.TCargo;
import com.smz.service.TCargoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TCargoServiceImpl extends ServiceImpl<TCargoDAO, TCargo> implements TCargoService {
    @Autowired
    private TCargoDAO tCargoDao;

    @Override
    public Page<TCargo> findPageTCargo(Integer current, Integer rows,Integer tShelvesNo,Integer damId,Integer wareId) {
        Page<TCargo> page=new Page<>(current,rows);
        Page<TCargo> data = tCargoDao.selectPage(page, new QueryWrapper<TCargo>().lambda().eq(TCargo::getShelvesNo,tShelvesNo).eq(TCargo::getDamId,damId).eq(TCargo::getWareId,wareId));
        return data;
    }


    @Override
    public Page<TCargo> findPageTCargoSearch(Integer current, Integer rows, Integer tShelvesNo, Integer cargoNo, Integer cargoState) {

        Page<TCargo> page=new Page<>(current,rows);
        if (cargoNo!=null){
            Page<TCargo> data = tCargoDao.selectPage(page, new QueryWrapper<TCargo>().lambda().eq(TCargo::getCatgoNo, cargoNo));
            return data;
        }else {
            if (tShelvesNo!=null&&cargoState!=null){
                Page<TCargo> data = tCargoDao.selectPage(page, new QueryWrapper<TCargo>().lambda().eq(TCargo::getShelvesNo,tShelvesNo).eq(TCargo::getStatus,cargoState));
                return data;
            }else if (tShelvesNo==null&&cargoState!=null){
                Page<TCargo> data = tCargoDao.selectPage(page, new QueryWrapper<TCargo>().lambda().eq(TCargo::getStatus,cargoState));
                return data;
            }else if (tShelvesNo!=null&&cargoState==null){
                Page<TCargo> data = tCargoDao.selectPage(page, new QueryWrapper<TCargo>().lambda().eq(TCargo::getShelvesNo,tShelvesNo));
                return data;
            }else {

                return null;
            }
        }
    }
}
